export default{
    prefix(){
        if(document.fullscreenEnabled)
            return "";
        else if(document.webkitFullscreenEnabled)
            return "webkit";
        else if(document.mozFullscreenEnabled)
            return "moz";
        else if(document.msFullscreenEnabled)
            return "ms";
        else
            return "";
    },
    isSupport(){
        return (document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullscreenEnabled || document.msFullscreenEnabled) == true;
    },
    requestFullscreen(element = document.documentElement){
        const methodName = this.prefix() == "" ? "requestFullscreen" : `${this.prefix()}RequestFullscreen`;
        element[methodName]();
    },
    exitFullscreen(){
        const methodName = this.prefix() == "" ? "exitFullscreen" : `${this.prefix()}ExitFullscreen`;
        document[methodName]();
    },
    isFullscreen(){
        return (document.fullscreenElement || document.webkitFullscreenElement || document.msFullscreenElement || document.mozFullscreenElement) != undefined;
    },
    screenChange(fn){
        const methodName = `on${this.prefix()}fullscreenchange`; 
        document[methodName] = (e) => {
            fn && fn(e, this.isFullscreen());
        };
    }
}